//
//  TPSinginViewController.m
//  Yimei
//
//  Created by xiaowu xiaowu on 2017/11/11.
//  Copyright © 2017年 xiaowu xiaowu. All rights reserved.
//

#import "TPSinginViewController.h"
#import "LoginContairView.h"
@interface TPSinginViewController ()
@property (nonatomic,strong)LoginContairView *contairView;
@end

@implementation TPSinginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"注册";
    [self setup];
}


-(void)setup{
    
    self.view.backgroundColor = TPAllBackgroundColor;
    _contairView = [LoginContairView getLoginContairView:self.view];
    _contairView.style = LoginContairViewStyleSinin;
    @weakify(self);
    [_contairView setBlock:^(NSInteger tag, UIButton *button) {
        @strongify(self);
        switch (tag) {
            case LoginContairViewStyleTelLogin:
            {
                [self getSinin:button];
            }
                break;
            case LoginContairViewStyleCode:
            {
                 [[TPRequestClient sharedClient]getRequestCodeButton:button mobile:self.contairView.viewModel.phone toType:LoginCodeStyleSingn];
            }
                break;
                
            case LoginContairViewStyleSinin:{
                 [self leftBtnAction:nil];
            }
                break;
         
            default:
                break;
        }
    }];
    
}


-(void)getSinin:(UIButton *)sender{
    
    [self.contairView layoutIfNeeded];
    [sender startSubmitting:@"注册中..."];
    
    [[TPRequestClient sharedClient]getLogin_get_phoneRegisterPhone:_contairView.viewModel.phone toPass:_contairView.viewModel.psw toCode:_contairView.viewModel.code name:_contairView.viewModel.name success:^(NSURLSessionDataTask *task, id responseObject, Responese *respone) {
        
        [sender stopSubmitting];
        [self.view xw_hideTitle:respone.message];
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self leftBtnAction:nil];
        });
        
    } failure:^(NSURLSessionDataTask *task, NSError *error, Responese *respone) {
        [sender stopSubmitting];
        [self.view xw_hideTitle:respone.message];
        
    } nonetWork:^(NSURLSessionDataTask *task, NSError *error) {
        [sender stopSubmitting];
        [self.view xw_hideTitle:error.localizedDescription];
    }];
}
@end
